package router

import (
    "log"
    
    "github.com/gin-gonic/gin"
    "generator-tool/controller"
    "generator-tool/service"
    "generator-tool/repository"
    "generator-tool/config" // 导入全局数据库配置
)

// SetupGeneratedRoutes 注册所有生成的路由
func SetupGeneratedRoutes(v1 *gin.RouterGroup) {
    db := config.GetDB() // 使用全局数据库连接
    // ShGood 路由
    ShGoodRepo := repository.NewShGoodRepository(db)
    ShGoodService := service.NewShGoodService(ShGoodRepo)
    ShGoodController := controller.NewShGoodController(ShGoodService)
    
    v1.POST("/SHGOODs", ShGoodController.Create)
    v1.GET("/SHGOODs", ShGoodController.GetAll)
    v1.GET("/SHGOODs/:id", ShGoodController.GetByID)
    v1.PUT("/SHGOODs/:id", ShGoodController.Update)
    v1.DELETE("/SHGOODs/:id", ShGoodController.Delete)
    // ShGoodsCategory 路由
    ShGoodsCategoryRepo := repository.NewShGoodsCategoryRepository(db)
    ShGoodsCategoryService := service.NewShGoodsCategoryService(ShGoodsCategoryRepo)
    ShGoodsCategoryController := controller.NewShGoodsCategoryController(ShGoodsCategoryService)
    
    v1.POST("/SHGOODSCATEGORYs", ShGoodsCategoryController.Create)
    v1.GET("/SHGOODSCATEGORYs", ShGoodsCategoryController.GetAll)
    v1.GET("/SHGOODSCATEGORYs/:id", ShGoodsCategoryController.GetByID)
    v1.PUT("/SHGOODSCATEGORYs/:id", ShGoodsCategoryController.Update)
    v1.DELETE("/SHGOODSCATEGORYs/:id", ShGoodsCategoryController.Delete)
    
    log.Println("✅ 路由注册完成")
}

// 使用方法示例
/*
func main() {
    // 初始化数据库
    config.InitDatabase()
    
    // 初始化路由
    r := gin.Default()
    v1 := r.Group("/api/v1")
    
    // 注册所有生成的路由
    SetupGeneratedRoutes(v1)
    
    // 启动服务器
    log.Println("🚀 服务器启动在 :8080")
    r.Run(":8080")
}
*/